<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>新增企业</title>
<link rel="stylesheet" type="text/css" href="../../css/bootstrap.min.css">
<style type="text/css">
	#changeCompInfoDiv{
		margin-top:400px;
		width:600px;
		margin:0 auto;
	}
	#div1{
		width:210px;
		margin:0 auto;
		margin-top:30px;
		font-size:32px;
	}
	#td1{
		width:160px;
	}
	#td2{
		width:170px;
	}
	#td3{
		width:220px;
	}
	#bt1{
		margin-left:210px;
		width:150px;
	}
	#tabel1{
		margin-top:50px;
	}
</style>
</head>
	<body>
		<div>
			<div id="div1">
				<p>企业信息修改</p>
			</div>
			<div id="changeCompInfoDiv">
				<form onsubmit="return check()">
					<table id="tabel1" class="table table-bordered">
						<tr>
							<td id="td1">企业登录名：</td>
							<td id="td2">
								<input id="compName" type="text" onblur="checkCompName()" />
							</td>
							<td id="td3">
								<label id="label1" class="help-block">待验证</label>
							</td>
						</tr>
			
						<tr>
							<td>企业登录密码：</td>
							<td>
								<input id="password" class="input-xlarge" type="password" onblur="checkPassword()"  placeholder="请输入新密码"/>
							</td>
							<td>
								<label id="passwordMessage">支持字母和数字组合</label>
							</td>
						</tr>
						<tr>
							<td>企业名称：</td>
							<td>
								<input id="companyName" class="input-xlarge" onblur="checkCompanyName()"  type="text" />
							</td>
							<td>
								<label id="companyNameMessage" class="help-block">和上一步输入密码一致</label>
							</td>
						</tr>
						<tr>
							<td>企业楼层位置：</td>
							<td>
								<input id="companyAddress" class="input-xlarge" onblur="checkCompanyAddress()"  type="text" />
							</td>
							<td>
								<label id="companyAddressMessage" class="help-block">和上一步输入密码一致</label>
							</td>
						</tr>
						<tr>
							<td>企业联系人：</td>
							<td>
								<input id="companyBoss" class="input-xlarge" type="text" onblur="checkCompanyBoss()"  />
							</td>
							<td>
								<label id="companyBossMessage" class="help-block">请输入中文</label>
							</td>
						</tr>
						<tr>
							<td>企业联系电话：</td>
							<td>
								<input id="companyTel" class="input-xlarge" type="text"  onblur="checkTel()" />
							</td>
							<td>
								<label id="companyTelMessage" class="help-block">请输入有效联系方式</label>
							</td>
						</tr>
						<tr>
							<td colspan="3">
								<input type="button" id="bt1" class="btn btn-success" value="提交" />
							</td>
						</tr>
					</table>
				</form>
			</div>
		</div>
	</body>
	<script type="text/javascript">
		window.onload=function(){
			getCompInfo();
		}
		function getCompInfo(){
			$.ajax({
				   type: "POST",
				   url: "***.do",
				   success: function(msg){
				     alert( "Data Saved: " + msg );
				   }
			});
		}
		function check() {
			var flag = checkCompName() && checkPassword() && checkNewPassword() && checkCompanyBoss() &&checkTel()&&checkCompanyName()&&checkCompanyAddress();
			return flag;
		}
		function checkCompName(){
			var inputName=document.getElementById("compName").value;
			$.ajax({
				   type: "POST",
				   url: "***.do",
				   data: "inputName="+inputName,
				   success: function(msg){
				     if(msg==1){
				    	 document.getElementById("label1").innerHTML="已被占用，请重输";
				     }
				   }
			});
		}
		function checkPassword(){
			var password = document.getElementById("password").value;
			var passwordMessage = document.getElementById("passwordMessage");
			var eReg =  /^[a-zA-Z][a-zA-Z0-9]{5,19}$/;
			if (password.length == 0) {
				passwordMessage.innerHTML = "密码不能为空";
				return false;
			} else if (!eReg.test(password)) {
				passwordMessage.innerHTML = "密码必须以字母开头，且长度为6-20位";
				return false;
			} else {
				passwordMessage.innerHTML = "写对啦！";
				return true;
			}		
		}
		function checkCompanyName(){
			var companyName = document.getElementById("companyName").value;
			var companyNameMessage = document.getElementById("companyNameMessage");
			if (companyName.length == 0) {
				companyNameMessage.innerHTML = "公司名称不能为空";
				return false;
			} else if ((companyName.length) <= 3 || (companyName.length) >= 15) {
				companyNameMessage.innerHTML = "必须为3-15位";
				return false;
			} else {
				companyNameMessage.innerHTML = "写对啦！";
				return true;
			}
		}
		function checkCompanyAddress(){
			var companyAddress = document.getElementById("companyAddress").value;
			var companyAddressMessage = document.getElementById("companyAddressMessage");
			if (companyAddress.length == 0) {
				companyAddressMessage.innerHTML = "公司名称不能为空";
				return false;
			} else if ((companyAddress.length) <= 3||(companyAddress.length) >= 30) {
				companyAddressMessage.innerHTML = "必须为3-30位";
				return false;
			} else {
				companyAddressMessage.innerHTML = "写对啦！";
				return true;
			}
		}
		function checkCompanyBoss(){
			var companyBoss = document.getElementById("companyBoss").value;
			var companyBossMessage = document.getElementById("companyBossMessage");
			var eReg =   /^[\u4e00-\u9fa5]{3,15}$/;
			if (companyBoss.length == 0) {
				companyBossMessage.innerHTML = "联系人不能为空";
				return false;
			} else if (!eReg.test(companyBoss)) {
				companyBossMessage.innerHTML = "必须为3-15位的中文汉字";
				return false;
			} else {
				companyBossMessage.innerHTML = "写对啦！";
				return true;
			}
		}
		function checkTel() {
			var companyTel = document.getElementById("companyTel").value;
			var companyTelMessage = document.getElementById("companyTelMessage");
			var eReg = /^1[34578]\d{9}$/;
			if (companyTel.length == 0) {
				companyTelMessage.innerHTML = "电话号码不能为空";
				return false;
			} else if (!eReg.test(companyTel)) {
				companyTelMessage.innerHTML = "电话号码格式不正确";
				return false;
			} else {
				companyTelMessage.innerHTML = "写对啦！";
				return true;
			}
		}
	</script>
</html>